/** Interactive Surface  FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *
 *  @author Acer
 */
package utilities;

import java.awt.Dimension;
import java.awt.Toolkit;

/** Interactive Surface FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *  General Information about this class -
 *  Comments - When given the two angles from the cameras the exact coordinates will be returned as an array
 */
public class CoordinateFinder {

    private static int LENGTH;
    private static int HEIGHT;

    public CoordinateFinder() {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dim = toolkit.getScreenSize();
        CoordinateFinder.LENGTH = dim.width;
        CoordinateFinder.HEIGHT=dim.height;
    }

    public static int getLENGTH() {
        return LENGTH;
    }
    public static int getHEIGHT(){
        return HEIGHT;
    }

    public int[] getCoordinate(int relCase, double theta, double beeta) {
        double x = 0;
        double y = 0;
        int[] pos = new int[2];
//        pos[0] = -10000;// invalid
//        pos[1] = -10000;// invalid
//        if (theta == 90 || beeta == 0) {
//            return pos;
//        }
        x = LENGTH * Math.tan(beeta) / (Math.tan(theta) + Math.tan(beeta));
        y = LENGTH * Math.tan(beeta) * Math.tan(theta) / (Math.tan(theta) + Math.tan(beeta));

        pos[0] = (int) x;
        pos[1] = (int) y;

        return pos;
    }

    public int[] getCoordinateOld(int relCase, double theta, double beeta) {
        double x = 0;
        double y = 0;
        int[] pos = new int[2];
        pos[0] = -10;// invalid
        pos[1] = -10;// invalid
        if (theta == 0 || beeta == 0) {
            return pos;

        }
        // theta=Math.toRadians(theta);
        // beeta=Math.toRadians(beeta);
        int d = LENGTH / 4;
        // System.out.println("ssssssssssss");
        switch (relCase) {

            case 1:
                y = 3 * d * Math.tan(beeta) / (Math.tan(beeta) + Math.tan(theta));
                x = y / Math.tan(beeta);
                break;
            case 2:
                y = (d * Math.tan(beeta) * (8 * Math.tan(theta) - 3))
                        / (Math.tan(theta) - Math.tan(beeta));
                x = (d * (3 - 8 * Math.tan(beeta)))
                        / (Math.tan(theta) - Math.tan(beeta));
                break;
            case 3:
                y = (d * Math.tan(beeta) * (8 * Math.tan(theta) - 3))
                        / (Math.tan(theta) - Math.tan(beeta));
                x = (d * (3 - 8 * Math.tan(beeta)))
                        / (Math.tan(beeta) - Math.tan(theta));
                break;
            case 4:
                y = (3 * d * Math.tan(beeta)) / (Math.tan(beeta) + Math.tan(theta));
                x = 8 * d - (3 * d / (Math.tan(beeta) + Math.tan(theta)));
                break;
        }
        pos[0] = (int) x;
        pos[1] = (int) y;

        return pos;
    }
}
